
package com.mephi.model;


import com.mephi.util.AuxClass;
import com.mephi.util.Constants;
import com.mephi.util.PieceColor;


/**
 * An half of move for example 1. Nf3 is [WHITE 1 Nf3], 2. ... Nf6 is [BLACK 2 Nf6]
 * 
 * @author mephisto
 * 2011-06-09
 */
public class PieceMovement
{
	/**
	 * Constructs a PieceMovement which is a half part of Movement.
	 * 
	 * @param moveNumber to set the moveNumber
	 * @param pieceMovement to set the pieceMovement
	 * @param pieceColor the pieceColor to set (PieceColor.WHITE or PieceColor.BLACK)
	 * 
	 * @throws IllegalArgumentException if {@code moveNumber < 1 && moveNumber > 1000} 
	 * @throws NullPointerException if pieceMovement is null
	 */
	public PieceMovement(int moveNumber, String pieceMovement, PieceColor pieceColor)
	{
		setPieceColor(pieceColor);
		setMoveNumber(moveNumber);
		setPieceMovement(pieceMovement);
	}
	
	/**
	 * 
	 * @return the pieceColor (PieceColor.WHITE or PieceColor.BLACK)
	 */
	public PieceColor getPieceColor()
	{
		return pieceColor;
	}
	
	/**
	 * 
	 * @param pieceColor the pieceColor to set (PieceColor.WHITE or PieceColor.BLACK)
	 * @throws NullPointerException if pieceColor is null
	 */
	public void setPieceColor(PieceColor pieceColor)
	{
		AuxClass.checkArgument(pieceColor, new NullPointerException("pieceColor cannot be null!"));
		this.pieceColor = pieceColor;
	}
	
	/**
	 * Returns the number of move.
	 * 
	 * @return the moveNumber
	 */
	public int getMoveNumber()
	{
		return moveNumber;
	}
	
	/**
	 * 
	 * @param moveNumber to set the moveNumber
	 * @throws IllegalArgumentException if {@code moveNumber < 1 && moveNumber > 1000}
	 */
	public void setMoveNumber(int moveNumber)
	{
		if (moveNumber < 1 || moveNumber > 1000)
			throw new IllegalArgumentException("Number of move is invalid!");
		this.moveNumber = moveNumber;
	}
	
	/**
	 * 
	 * @return the PieceMovemnt(a proper move string representation)
	 */
	public String getPieceMovement()
	{
		return pieceMovement;
	}

	/**
	 * 
	 * @param pieceMovement to set the pieceMovement
	 * @throws NullPointerException if pieceMovement is null
	 */
	public void setPieceMovement(String pieceMovement)
	{
		AuxClass.checkArgument(pieceMovement, new NullPointerException("pieceMovement cannot be null!"));
		this.pieceMovement = pieceMovement;
	}
	
	/**
	 * Prints object representation in the standard short chess notation.
	 * 
	 * [WHITE 1 Nf3] is 1. Nf3 , [BLACK 2 Nf6] is 2. ... Nf6.
	 */
	@Override
	public String toString()
	{
		StringBuilder sB = new StringBuilder().append(moveNumber).append(Constants.DOT_STRING).append(Constants.SPACE_STRING);
		if (pieceColor.equals(PieceColor.BLACK))
			sB.append(Constants.THREE_DOT_STRING).append(Constants.SPACE_STRING);
		sB.append(pieceMovement);
			
		return sB.toString();
	}
	
	
	private PieceColor pieceColor;
	private int moveNumber = 0;
	private String pieceMovement;
}
